package org.drushpal.view.forms
{
	import flash.events.Event;
	
	import mx.events.CloseEvent;
	import mx.managers.PopUpManager;
	
	import org.drushpal.model.SettingsModel;
	import org.robotlegs.mvcs.Mediator;
	
	public class SettingsFormMediator extends Mediator
	{
		
		[Inject]public var settingsForm:SettingsForm;
		[Inject]public var settingsModel:SettingsModel;
		override public function onRegister():void{
			eventMap.mapListener(settingsForm,SettingsForm.EVENT_SAVE_SETTINGS,onSaveSettings);
			eventMap.mapListener(settingsForm,CloseEvent.CLOSE,onClose);
			settingsForm.settings = settingsModel.settings;
		}
		private function onSaveSettings(event:Event):void{
			settingsModel.settings.openInExternalBrowser = settingsForm.chkOpenInExtBrowser.selected;
			settingsModel.settings.updateRepoNotification = settingsForm.chkUpdateRepoNotification.selected;
			settingsModel.saveSettings();
		}
		private function onClose(event:CloseEvent):void{
			mediatorMap.removeMediatorByView(settingsForm);
			PopUpManager.removePopUp(settingsForm);
		}
	}
}